<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="/static/jQuery-1.11/jquery-1.11.3.min.js"></script>
    <script>
        $(function () {
            $('#login').click(function () {
                //发送ajax
                //获取到用户输入的用户名和密码
                var $usernameInput = $('#username');
                var $passwordInput = $('#password');
                var u = $usernameInput.val();
                var p = $passwordInput.val();
                //构成js对象作为下面请求的参数
                var paramString = {username:u,password:p};
                //发送jQuery的ajax请求
                $.post("/loginJson",paramString,function (data) {
                    //如果登录成功跳转页面
                    if (data.success){
                        location.href = "http://www.wolfcode.cn"
                    }else {
                        //如果登录失败则提示用户
                        $('#result').html(data.msg).css('color','red');
                    }
                });
            });
        });
    </script>
</head>
<body>
<span id="result"></span><br/>
    用户名:<input type="text" name="username" id="username"><br/>
    密码:<input type="text" name="password" id="password"><br/>
    <button id="login">登录</button>
</body>
</html>